<?php
class App_Module_Admin_Component_Structure_Tpl_Editform extends App_Module_Admin_Tpl_Block_Editform
{
	protected $_form = 'entity/structure';
	
	public function GetForm($cid, $category)
	{
		//Mozg::SubAction()->Add('RequiredJS', array($this, 'AddCatJS'), array(), 'AddCat');
		
		$this->cid = $cid;
		$this->category = $category;
		
		return $this->CreateForm($category);
	}

    protected function RenderBlock()
    {
    	Mozg::SubAction()->Add('RequiredJS', array($this, 'AddCatJS'), array(), 'AddCatJS');
    	
    	$this->block = parent::RenderBlock();
    	return $this->render('structure/_catformdata.phtml');
    }

    public function AddCatJS()
    {
    	return $this->render('structure/js/_addcat.js');
    }
    
	protected function GetActionUrl()
	{
		return array('module' => 'admin', 'ctrl' => 'structure', 'action' => 'save', 'cat' => $this->cid, 'subcat' => $this->category->GetId() );
	}
	
	protected function GetBackUrl()
	{
		return array('module' => 'admin', 'ctrl' => 'structure', 'action' => 'list', 'cat' => $this->cid);
	}
	
	protected function GetHeaderTitle()
	{
		if ($this->category->GetId())
		{
			$title = Mozg_Lang::_('EDIT_CATEGORY');
		}
		else
		{
			$title = Mozg_Lang::_('ADD_CATEGORY');
		}

		return $title;
	}
	
	protected function GetHeaderIcons()
	{
        $icons[0] = array(
        	'add' => array(
        					'title' => 'ADD',
        					'url' => Mozg_Router::Get('http')->Create(array('module' => 'admin', 'ctrl' => 'structure', 'action' => 'add', 'cat' => $this->cid))
        					),
        );
        
        if ($this->category->GetId() && (!$this->category->GetBlocked() || Mozg::User()->IsSuperUser()))
        {
	        $icons[1] = array(
	        	'delete' => array(
	        					'title' => 'DELETE_CATEGORY?',
	        					'url' => Mozg_Router::Get('http')->Create(array('module' => 'admin', 'ctrl' => 'structure', 'action' => 'del', 'cat' => $this->cid , 'subcat' => $this->category->GetId()))
	        					),
	        );
        }
        
        if ($this->category->GetId())
        {
	        $icons[1]['html'] = array(
	        					'title' => 'GO_TO_CONTENT_EDIT_FORM',
	        					'url' => Mozg_Router::Get('http')->Create(array('module' => 'admin', 'ctrl' => 'structure', 'action' => 'editbody', 'cat' => $this->cid , 'subcat' => $this->category->GetId()))
	        					);
        }
        
        return $icons;
	}
}